/**
 * Copyright (c) 2016-2019 九点科技 All rights reserved.
 *
 * https://www.9dyun.cn
 *
 * 版权所有，侵权必究！
 */
package com.dian.modules.common.server.impl;

import com.dian.common.server.CommonService;
import com.dian.modules.common.dto.ConverDto;
import com.dian.modules.common.server.BusService;
import com.dian.modules.enums.sys.Ent_EntTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;


/**
 * 通用服务类信息
 *
 * @author  xiaolai@9dyun.cn
 */
@Service("BusService")
public class BusServiceImpl implements BusService {
    /**
     * 日志打印
     */
    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private CommonService commonService;

    @Override
    public ConverDto convert(ConverDto converDto){
        if(commonService.getUser().getEntType().equals(Ent_EntTypeEnum.DEALER.getCode())){
            BigDecimal qtyNum=converDto.getQtyNum();
            if(qtyNum==null){
                qtyNum=new BigDecimal("0");
                converDto.setQtyNum(qtyNum);
            }
            BigDecimal auxNum=converDto.getAuxNum();
            if(auxNum==null){
                auxNum=new BigDecimal("0");
                converDto.setAuxNum(auxNum);
            }

            BigDecimal converUnit1=converDto.getConverUnit1();
            if(converUnit1==null){
                converUnit1=new BigDecimal("0");
                converDto.setConverUnit1(converUnit1);
            }

            BigDecimal converUnit2=converDto.getConverUnit2();
            if(converUnit2==null){
                converUnit2=new BigDecimal("0");
                converDto.setConverUnit2(converUnit2);
            }

            BigDecimal baseNum=qtyNum.multiply(converUnit1).add(auxNum.multiply(converUnit2));
            converDto.setBaseNum(baseNum);
            return converDto;
        }
        return null;
    }


}
